package net.cyndeline.GUI.canvas

import net.cyndeline.GUI.rendering.{RenderJob, RenderTarget}
import javafx.scene.canvas.GraphicsContext

/**
 * Draws 2D sprites onto a graphics context.
 */
class Renderer2D(context: GraphicsContext) extends RenderTarget {

  /** Renders every graphic in the render job. */
  def render(job: RenderJob): Unit = {
    var i = 0

    while (i < job.jobs.size) {
      val jobLayer = job.jobs(i)
      var j = 0

      while (j < jobLayer.size) {
        val render = jobLayer(j)
        context.drawImage(render.view, render.x.toDouble, render.y.toDouble)
        j += 1
      }

      i += 1
    }
  }
}
